package org.javaboy.exception_demo2.exception;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.HashMap;
import java.util.Map;

@RestControllerAdvice
public class GlobalException {

    @ExceptionHandler(ArithmeticException.class)
    public Map<String, Object> arithmeticException(ArithmeticException e) {
        Map<String, Object> map = new HashMap<>();
        map.put("msg", e.getMessage());
        return map;
    }

    @ModelAttribute("info")
    public Map<String,Object> projectInfo() {
        Map<String, Object> map = new HashMap<>();
        map.put("version", "0.0.1");
        map.put("name", "exception_demo02");
        return map;
    }

}
